package lesson7;

import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

public class MyThreadPool {

    static AtomicInteger count = new AtomicInteger(0);

    public static void main(String[] args) {

        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 10, 0, TimeUnit.SECONDS, new ArrayBlockingQueue(100),
                (r, executor) -> {
                    System.out.println("自定义线程池拒绝策略..");
                });

        Runnable runnable = () -> {
            while(Thread.currentThread().isInterrupted()){
                System.out.println("线程被中断。。。");
                return;
            }
            System.out.println("count :  " + count.incrementAndGet());
        };
        for(int i = 0; i <= 99; i++){
            threadPoolExecutor.execute(runnable);
        }
        Thread thread = new Thread(runnable);
        thread.stop();
        //threadPoolExecutor.shutdown();
        List<Runnable> shutdownRunnable = threadPoolExecutor.shutdownNow();
        System.out.println("thread pool is shutdown : " + threadPoolExecutor.isShutdown());
        System.out.println("thread pool is terminating : " + threadPoolExecutor.isTerminating());
        System.out.println("thread pool is terminated : " + threadPoolExecutor.isTerminated());
    }

    /*public void setMethod(){
        this
    }*/
}
